home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
me_cd.zip
/
MUTT.DOC
< prev
next >
Wrap
Lisp/Scheme
|
1988-10-24
|
25KB
|
640 lines
========================================================================
== The Mutt Programming Language Craig Durland 9/88 ==
========================================================================
symbol action
( evaluate expression
) end expression
{ start pgm
} end pgm
SYNTAX
pgm : {exp [exp ...]}, {}
exp : (fcn [args]), (var [args]), var, const, ()
const : number (123, 0xAbC), string ("abc", 'abc'), TRUE, FALSE
arg : block
block : pgm, exp or const
fcn : a Mutt function (such as + or while) or defined function.
======================================================================
Return Values
======================================================================
All blocks return a value. Pgms return the value of the last exp
executed.
The class of a return value can be one of:
BOOLEAN TRUE or FALSE
BLOB a pointer to a block of data
NUMBER 32 bit signed integer
STRING a bunch of characters
VOID a type of nothing
======================================================================
Variables (aka vars)
======================================================================
CREATION
Vars must be created (and allocated) before they can be used.
Global vars are initialized to:
bool: FALSE
INT, int, byte: 0
string: ""
Local vars are NOT initialized (ie they contain garbage when
created).
EVALUATION & ASSIGNMENT
Vars behave like fcns, ie (var) evaluates the var (returns its value)
and (var val) passes val to the var for assignment. (var val)
returns val. If you just want to evaluate a var, you can treat it
like a const - ie var is equivalent to (var). Note, however, doing
this may cause logic bugs if var also happens to be the name of a
const (since the const is locked out). See GOTCHAS. In some cases,
(var) and var don't mean the same thing - see pointer.
Cascading assignment: you can assign multiple vars the same value.
eg (int x y z)(x (y (z 123))) assigns 123 to x, y and z.
eg (int x)(string s 20)(x (atoi (s "123"))) sets s to "123" and x
to 123.
SCOPE
The scope of a variable is the same as the pgm it is allocated in.
A variable allocated outside of a fcn is global - ie anybody can get
at it. Global variables are local to the file (and any included
file(s)) they are allocated in.
For example:
If foo.mut contains:
(int foo) ; declare and allocate global var "foo"
(defun "hoho" {(int bar)(bar foo)})
(foo 123) ; assign 123 to foo
(load "foo.mut") will create a global var foo. (hoho)
creates bar and sets it to 123. hoho is done and bar is deallocated.
foo remains allocated and equal to 123.
======================================================================
Functions and Keywords
======================================================================
Everything in this list is a function except those that have a return
class of zip.
KEYWORD [arg class(s) : return class]
; a comment that extends to the end of the line
(== value value ...) [STRINGs, NUMBERs or BOOLEANs : BOOLEAN]
Test 2 or more items for equality.
You can only compare like types - eg (== "123" 123) is illegal.
eg (== foo 1), (== "one" "two"), (== (+ foo 3) bar 5).
(!= value value) Same as == but nonequality. Only 2 items.
(< value value) [NUMBER NUMBER : BOOLEAN]
(<= value value) [NUMBER NUMBER : BOOLEAN]
(> value value) [NUMBER NUMBER : BOOLEAN]
(>= value value) [NUMBER NUMBER : BOOLEAN]
(+ values) [NUMBERs : NUMBER]
add a bunch of numbers eg (+ 1 2 3 4) => 1+2+3+4
(- values) [NUMBERs : NUMBER]
subtract a bunch of numbers eg (- 1 2 3 4) => 1-2-3-4 = -8
(* values) multiply a bunch of numbers [NUMBERs : NUMBER]
(/ values) divide a bunch of numbers [NUMBERs : NUMBER]
(+= var values) [TOKEN, NUMBERs : NUMBER]
Add value(s) to var and assign it back to the var. Returns the result.
Short hand for (var (+ var values)).
eg (+= foo 1) (+= foo fud 3)
(-= var values) Subtract value from var. [TOKEN, NUMBERs : NUMBER]
(*= var values) Multiply var by value. [TOKEN, NUMBERs : NUMBER]
(/= var values) Divide var by value. [TOKEN, NUMBERs : NUMBER]
"string"
String constant.
Special characters:
\ quote the next character. "\\" => '\' "\^" => '^'
^ convert the next character to a control character (make sure that
the letter is UPPERCASE!). eg "^A"
Note: escape == ^[.
'string'
String constant.
No special characters except '' reduces to ' ie if you need a string
like "don't" use 'don''t'.
This form is handy for regular expressions.
(and values) [BOOLEANs : BOOLEAN]
Logically and a bunch of things
The first FALSE value will terminate (ie the rest of the and will
not be evaluated). eg (and (previous-line) (foo))
(array type name dimensions) [TOKEN TOKEN NUMBERs [TOKEN NUMBERs] : zip]
Create an array. Types allowed: bool, int, INT, string.
(array int x 5 z 7) creates two arrays: x with 5 ints and z with 7.
(array INT y 2 3) creates an array with 2 rows of 3 INTs each.
(array string s 5 80) creates 5 strings that can each hold up to 80
characters.
(x 3 123) sets the third element of x to 123.
(x 3) returns 123.
(arg n) [NUMBER : any class]
Get the nth argument from the parameter list.
The arguments are numbered 0,1...,(nargs)-1
eg (foo 1 "two" (three)) has 3 arguments: numeric 1, string "two" and
whatever fcn three returns. (arg 0) returns 1, (arg 1) returns
"two", (arg 2) returns result of (three). (arg 3), (arg -1), etc
error.
Notes:
You cannot set a arg unless it is a pointer.
See also: ask, defun, nargs.
(ask prompt) [STRING : STRING]
Get the next argument from the argument list; if the argument list is
empty, query the user.
eg if (foo (ask "foo = ")) is in fud then (fud "hoho") will pass "hoho"
to foo. (fud) will cause the message "foo = " to appear and will wait
for a response to assign to foo.
You can force the pgm to query the user with (ask-user). If you do
this, you will need one per ask. The next unmodified ask will behave
as above.
See also: arg, ask-user, atoi.
(ask-user) [zip : VOID]
The next ask will query the keyboard and not the program args.
Turned off after every ask.
See also: ask.
(atoi string) [STRING : NUMBER]
Convert a string to a number. If the string is not numeric,
atoi returns 0.
eg (foo (atoi (ask "A number please: ")))
Note: To convert a number into a string, use concat.
eg (string s 20)(s (concat 123)) will convert numeric 123 into a
string and assign it to s.
See also: ask.
(bool var [var ...]) [TOKENS : zip]
Evaluation & assignment: var, (var value) [TOKEN [BOOLEAN] : BOOLEAN]
Allocate 1 or more boolean variables.
Example: (bool foo)(foo TRUE) ; set foo TRUE
See also: int, string.
(break) [zip : zip]
Get out of the smallest enclosing for or while loop. The loop then
retuns the value of the last block executed.
See also: continue, for, while.
(byte var [var ...]) [TOKENs : zip]
Evaluation & assignment: var, (var value) [TOKEN [NUMBER] : NUMBER]
Allocate 8 bit unsigned integers.
The range of a int is [0 : 255].
Note that a NUMBER may not fit in a byte.
See also: int, INT.
(case test body ...)
[[BOOLEAN, block, [BOOLEAN, block ...]] : last block executed]
Same as nested if's. If the test is TRUE then the next block is
executed and the case is ended. Otherwise the next block is skipped
and the cycle repeats.
eg
(string str 50)(str (ask "str = "))
(case
(== str "one")(msg "number 1")
(== str "foo")(msg "bar")
TRUE (msg str " is not something I know about.")
)
See also: switch
(concat parameters) [anything : STRING]
Concatenate parameters.
eg (concat "foo = " foo) return "foo = 123" if foo is 123 or "123".
(const name value [name value ...]) [TOKEN BOOLEAN|NUMBER|STRING : zip]
Create one or more constants. Used like other constants